#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;

#define in read<int>()
#define inn read<ll>()
#define pii pair<int,int>
#define fi first
#define se second
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout);
#define pb push_back

template <typename T>
T read(){
	T x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}

const int N = 1010;

ll t[65];
int ans,n;

struct stone{ll num;int val;}s[N];
bool operator < (stone a,stone b){return a.val > b.val;}

bool insert(ll x){
	for(int i = 62;~i;i--)
		if(x >> i & 1){
			if(t[i]) x ^= t[i];
			else return t[i] = x,1;
		}
	return 0;
}

int main (){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in;
	for(int i = 1;i <= n;i++) s[i].num = inn,s[i].val = in;
	sort(s+1,s+n+1);
	for(int i = 1;i <= n;i++)
		if(insert(s[i].num))
			ans += s[i].val;
	printf("%d\n",ans);
	return 0;
}

